package com.example.demo3.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo3.entity.CodeAction;
import com.example.demo3.mapper.CodeActionMapper;
import com.example.demo3.mapper.SparePartsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 行动码 服务实现类
 * </p>
 *
 * @author xsyuan
 * @since 2020-03-27
 */
@Service
public class CodeActionService extends ServiceImpl<CodeActionMapper, CodeAction>{


    @Resource
    private SparePartsMapper sparePartsMapper;
    @Resource
    private CodeActionMapper codeActionMapper;

    /**
     * 分页查询
     * @param pageindex
     * @param pagesize
     * @return
     */
    public Page<CodeAction> getSelectPage(int pageindex, int pagesize){
        Page<CodeAction> page=new Page<CodeAction>().setCurrent(pageindex).setSize(pagesize);
        QueryWrapper<CodeAction> queryWrapper=new QueryWrapper<CodeAction>()
                .orderByDesc("CODE");
        codeActionMapper.selectPage(page,queryWrapper);
        return page;
    }

    public int countPage(Map<Object,Object> map){
        return codeActionMapper.countPage(map);
    }

    public List<CodeAction> queryPage(Map<Object,Object> map){
        return codeActionMapper.queryPage(map);
    }
    /**
     * 新增
     * @param codeAction
     */
    public void insert(CodeAction codeAction){
        codeAction.setId(sparePartsMapper.getUUID());
        codeActionMapper.insert(codeAction);
    }

    /**
     *修改
     * @param codeAction
     */
    public void update(CodeAction codeAction){
        codeActionMapper.updateById(codeAction);
    }

    /**
     * 删除
     * @param map
     */
    public void delete(Map<String,Object> map){
        codeActionMapper.updateByIds(map);
    }

    /**
     * @description  通过Map查询【行动码】集合
     * @author: xsyuan
     * @date: 2020/3/28 10:51
     * @param  map
     * @return  List
     */
    public List<CodeAction> getByMap(Map<String,Object> map){
        return codeActionMapper.findByMap(map);
    }

     /**
       * @description 通过Map查询
       * @author: xsyuan
       * @date: 2020/3/28 17:19
       * @param map
       * @return boolean
       */
    public boolean checkByMap(Map<String,Object> map){
        return codeActionMapper.checkByMap(map);
    }
}
